package com.orange.score.activity.entry;

import android.content.Context;
import android.text.SpannableStringBuilder;
import android.text.style.ForegroundColorSpan;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import com.orange.score.model.match.Match;
import com.orange.score.model.match.MatchGroup;
import java.util.List;

public class RealtimeMatchExpandableListAdapter extends BaseExpandableListAdapter
{
  static int CARD_WIDTH;
  static int MAX_TEAM_NAME_WIDTH;
  private static final String TAG = RealtimeMatchExpandableListAdapter.class.getName();
  private Context context;
  FollowMatchCallBack followMatchCallBack;
  private List<MatchGroup> groups;

  static
  {
    MAX_TEAM_NAME_WIDTH = 100;
    CARD_WIDTH = 20;
  }

  public RealtimeMatchExpandableListAdapter(List<MatchGroup> paramList, Context paramContext, FollowMatchCallBack paramFollowMatchCallBack)
  {
    this.context = paramContext;
    this.groups = paramList;
    this.followMatchCallBack = paramFollowMatchCallBack;
  }

  private boolean hasCard(String paramString)
  {
    int i;
    if ((paramString != null) && (paramString.length() > 0) && (Integer.parseInt(paramString) > 0))
      i = 1;
    while (true)
    {
      return i;
      i = 0;
    }
  }

  private void setCardData(String paramString, View paramView, TextView paramTextView)
  {
    if (hasCard(paramString))
    {
      paramTextView.setText(paramString);
      paramTextView.setVisibility(0);
    }
    while (true)
    {
      return;
      paramTextView.setVisibility(8);
    }
  }

  public Object getChild(int paramInt1, int paramInt2)
  {
    return ((MatchGroup)this.groups.get(paramInt1)).children.get(paramInt2);
  }

  public long getChildId(int paramInt1, int paramInt2)
  {
    return paramInt2;
  }

  public View getChildView(int paramInt1, int paramInt2, boolean paramBoolean, View paramView, ViewGroup paramViewGroup)
  {
    Holder localHolder;
    Match localMatch;
    String str;
    SpannableStringBuilder localSpannableStringBuilder;
    if (paramView != null)
    {
      localHolder = (Holder)paramView.getTag();
      localMatch = (Match)((MatchGroup)this.groups.get(paramInt1)).children.get(paramInt2);
      localHolder.followButton.setOnClickListener(new View.OnClickListener(this, localMatch, localHolder)
      {
        public void onClick()
        {
          boolean bool;
          this.this$0.followMatchCallBack.followUnfollowMatch(this.val$match);
          Button localButton = this.val$holder.followButton;
          if (this.val$holder.followButton.isSelected())
            bool = false;
          while (true)
          {
            localButton.setSelected(bool);
            return;
            bool = true;
          }
        }
      });
      if (!(localMatch.isFollow()))
        break label942;
      localHolder.followButton.setSelected(true);
      localHolder.homeTeamName.setText(localMatch.getHomeTeamName());
      localHolder.awayTeamName.setText(localMatch.getAwayTeamName());
      localHolder.leagueName.setText(localMatch.getLeagueName());
      localHolder.leagueName.setTextColor(localMatch.getLeagueColor());
      localHolder.matchStartTime.setText(localMatch.getDateString());
      localHolder.homeTeamRed.setText(localMatch.getHomeTeamRed());
      localHolder.homeTeamYellow.setText(localMatch.getHomeTeamYellow());
      localHolder.awayTeamRed.setText(localMatch.getAwayTeamRed());
      setCardData(localMatch.getHomeTeamYellow(), paramView, localHolder.homeTeamYellow);
      setCardData(localMatch.getHomeTeamRed(), paramView, localHolder.homeTeamRed);
      setCardData(localMatch.getAwayTeamRed(), paramView, localHolder.awayTeamRed);
      setCardData(localMatch.getAwayTeamYellow(), paramView, localHolder.awayTeamYellow);
      int i = MAX_TEAM_NAME_WIDTH;
      if (!(hasCard(localMatch.getHomeTeamYellow())))
        i += CARD_WIDTH;
      if (!(hasCard(localMatch.getHomeTeamRed())))
        i += CARD_WIDTH;
      localHolder.homeTeamName.setMaxWidth(i);
      int j = MAX_TEAM_NAME_WIDTH;
      if (!(hasCard(localMatch.getAwayTeamYellow())))
        j += CARD_WIDTH;
      if (!(hasCard(localMatch.getAwayTeamRed())))
        j += CARD_WIDTH;
      localHolder.awayTeamName.setMaxWidth(j);
      if (!(localMatch.needDisplayScore()))
        break label1012;
      str = localMatch.getMatchStatusOrMinutString();
      if (!(str.contains("'")))
        break label986;
      localSpannableStringBuilder = new SpannableStringBuilder();
      localSpannableStringBuilder.append(str);
      localSpannableStringBuilder.setSpan(new ForegroundColorSpan(localMatch.getMatchStatusColor()), 0, str.length() - 1, 18);
      if (System.currentTimeMillis() / 1000L % 2L != 0L)
        break label954;
      localSpannableStringBuilder.setSpan(new ForegroundColorSpan(-65536), str.length() - 1, str.length(), 18);
      localHolder.matchStatus.setText(localSpannableStringBuilder);
      localHolder.matchStatus.setVisibility(0);
      localHolder.matchScore.setText(localMatch.getHomeTeamScore() + ":" + localMatch.getAwayTeamScore());
      localHolder.matchScore.setVisibility(0);
      localHolder.matchScore.setTextColor(localMatch.getMatchScoreColor());
      localHolder.matchStatusOnly.setVisibility(4);
      localHolder.firstHalfScore.setText("(" + localMatch.getHomeTeamFirstHalfScore() + ":" + localMatch.getAwayTeamFirstHalfScore() + ")");
      if (!(localMatch.hasFirstHalfScore()))
        break label1068;
      localHolder.firstHalfScore.setVisibility(0);
      if (!(localMatch.hasChupan()))
        break label1080;
      localHolder.chupan.setVisibility(0);
      localHolder.chupan.setText(localMatch.getCrownChupanString());
      if (!(localMatch.isScoreJustUpdate()))
        break label1092;
      Log.d(TAG, "score is just updated, set special background");
      paramView.setBackgroundResource(2130837637);
    }
    while (true)
    {
      while (true)
      {
        while (true)
        {
          while (true)
          {
            while (true)
            {
              while (true)
              {
                while (true)
                {
                  while (true)
                  {
                    return paramView;
                    localHolder = new Holder();
                    paramView = LayoutInflater.from(this.context).inflate(2130903091, null);
                    localHolder.homeTeamName = ((TextView)paramView.findViewById(2131558588));
                    localHolder.awayTeamName = ((TextView)paramView.findViewById(2131558591));
                    localHolder.homeTeamRed = ((TextView)paramView.findViewById(2131558587));
                    localHolder.awayTeamRed = ((TextView)paramView.findViewById(2131558593));
                    localHolder.homeTeamYellow = ((TextView)paramView.findViewById(2131558586));
                    localHolder.awayTeamYellow = ((TextView)paramView.findViewById(2131558594));
                    localHolder.leagueName = ((TextView)paramView.findViewById(2131558583));
                    localHolder.chupan = ((TextView)paramView.findViewById(2131558592));
                    localHolder.matchStatus = ((TextView)paramView.findViewById(2131558585));
                    localHolder.matchStatusOnly = ((TextView)paramView.findViewById(2131558589));
                    localHolder.matchStartTime = ((TextView)paramView.findViewById(2131558584));
                    localHolder.matchScore = ((TextView)paramView.findViewById(2131558590));
                    localHolder.firstHalfScore = ((TextView)paramView.findViewById(2131558595));
                    localHolder.followButton = ((Button)paramView.findViewById(2131558582));
                    paramView.setTag(localHolder);
                  }
                  label942: localHolder.followButton.setSelected(false);
                }
                label954: localSpannableStringBuilder.setSpan(new ForegroundColorSpan(-3355444), str.length() - 1, str.length(), 18);
              }
              label986: localHolder.matchStatus.setText(str);
              localHolder.matchStatus.setTextColor(localMatch.getMatchStatusColor());
            }
            label1012: localHolder.matchStatusOnly.setText(localMatch.getMatchStatusString());
            localHolder.matchStatusOnly.setVisibility(0);
            localHolder.matchStatusOnly.setTextColor(localMatch.getMatchStatusColor());
            localHolder.matchStatus.setVisibility(4);
            localHolder.matchScore.setVisibility(4);
          }
          label1068: localHolder.firstHalfScore.setVisibility(4);
        }
        label1080: localHolder.chupan.setVisibility(4);
      }
      label1092: paramView.setBackgroundResource(2130837700);
    }
  }

  public int getChildrenCount(int paramInt)
  {
    return ((MatchGroup)this.groups.get(paramInt)).children.size();
  }

  public Object getGroup(int paramInt)
  {
    return this.groups.get(paramInt);
  }

  public int getGroupCount()
  {
    return this.groups.size();
  }

  public long getGroupId(int paramInt)
  {
    return paramInt;
  }

  public View getGroupView(int paramInt, boolean paramBoolean, View paramView, ViewGroup paramViewGroup)
  {
    TitleHolder localTitleHolder;
    if (paramView != null)
      localTitleHolder = (TitleHolder)paramView.getTag();
    while (true)
    {
      String str = ((MatchGroup)this.groups.get(paramInt)).leagueName;
      localTitleHolder.leagueName.setText(str);
      localTitleHolder.groupImage.setBackgroundResource(2130837695);
      if (paramBoolean)
        localTitleHolder.groupImage.setBackgroundResource(2130837697);
      return paramView;
      localTitleHolder = new TitleHolder();
      paramView = LayoutInflater.from(this.context).inflate(2130903090, null);
      localTitleHolder.leagueName = ((TextView)paramView.findViewById(2131558533));
      localTitleHolder.groupImage = ((ImageView)paramView.findViewById(2131558532));
      paramView.setTag(localTitleHolder);
    }
  }

  public boolean hasStableIds()
  {
    return false;
  }

  public boolean isChildSelectable(int paramInt1, int paramInt2)
  {
    return true;
  }

  public void updateList(List<MatchGroup> paramList)
  {
    this.groups = paramList;
  }

  static class Holder
  {
    TextView awayTeamName;
    TextView awayTeamRed;
    TextView awayTeamYellow;
    TextView chupan;
    TextView firstHalfScore;
    Button followButton;
    TextView homeTeamName;
    TextView homeTeamRed;
    TextView homeTeamYellow;
    TextView leagueName;
    TextView matchScore;
    TextView matchStartTime;
    TextView matchStatus;
    TextView matchStatusOnly;
  }

  static class TitleHolder
  {
    ImageView groupImage;
    TextView leagueName;
  }
}